#include<bits/stdc++.h>
// #define int long long
#define rep(i,a,b) for(int i(a);i<=(b);++i)
#define req(i,a,b) for(int i(a);i>=(b);--i)
#define sort stable_sort
using namespace std;
char buf[1<<23],*p1=buf,*p2=buf;
#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
template<typename TP> inline TP read(TP &num)
{
	TP x=0;
	int f=0;
	char ch=getchar();
	while(ch<48||ch>57) f|=ch=='-',ch=getchar();
	while(48<=ch&&ch<=57) x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return num=f?-x:x;
}
template<typename ...Args> inline void read(Args &...args)
{
	(read(args),...);
}
template<typename TP> inline void write(TP x)
{
	(x<0)?(putchar('-'),x=-x):0;
	(x>9)?(write(x/10),0):0;
	putchar((x%10)^48);
}
template<typename TP> inline void writeln(TP x)
{
	write<TP>(x);
	puts("");
}
int lim,n;
signed main()
{
	freopen("c.in","r",stdin);
	freopen("c.out","w",stdout);
	read(lim,n);
	vector<array<int,4>> a(n+1);
	rep(i,1,n)
	{
		int A1,A2,A3,A4; read(A1,A2,A3,A4);
		a[i][0]=A1,a[i][1]=A2,a[i][2]=A3,a[i][3]=A4;
	}
	int ans=0;
	rep(v1,1,lim) rep(v2,1,lim) rep(v3,1,lim) rep(v4,1,lim)
	{
		int ok=1;
		rep(_,1,n)
	{
		int cnt=(v1>a[_][0])+(v2>a[_][1])+(v3>a[_][2])+(v4>a[_][3]);
		ok&=cnt>=3;
	}ans+=ok;}
	write(ans);
	return 0;
}
